<?php

namespace Home\Controller;

/**
 * Description of DealerManageController.class控制器实例
 *
 * @author zhangzhen
 * @date 2017-01-03
 */
class DealerPageController extends DealerParentController {

    protected function _initialize() {
        $this->validateUtil = new \Org\Util\Validate();
        $this->checkLanguage();
    }
    /**
     * 登录页面
     * @modify zhangzhen 2017-01-04
     */
    public function index() {
        $this->checkLogin();
        $this->checkOverTime();
        $this->assignUser();
        $this->display();
    }
    /**
     * 登录页面
     * @modify zhangzhen 2017-01-04
     */
    public function login() {
        $this->checkLogout();
        $this->display();
    }

    /**
     * 忘记密码页面
     * @modify zhangzhen 2017-01-04
     */
    public function forget() {
        $this->checkLogout();
        $this->display();
    }

    /**
     * 重置密码页面
     * @modify songanwei 2016-01-12
     */
    public function reset() {
        $this->checkLogout();
        $validator = new \Org\Util\Validate();
        $param = I('get.');
        $sessionId = $param['id'];
        $mobile = $param['mobile'];
        $idValidatePass = $validator->validate($sessionId, 'notempty,sessionId');

        if (!$idValidatePass) {
            $this->clearResetSession();
            redirect('/forgetPassword.html');
        }

        session_id($sessionId);
        $isMobile = $this->validateUtil->validate($mobile, 'notempty,mobile');
        $sessionMobile = session(C('RESET_PASSWORD_SEND_MOBILE'));

        if (empty($sessionMobile)) {
            $this->clearResetSession();
            redirect('/forgetPassword.html');
        }

        if ($isMobile) {
            // 手机已验证验证码超时情况,可直接跳转
            $validatePass = session(C('RESET_PASSWORD_VALIDATE_PASSWORD'));
            if ($sessionMobile != $mobile || empty($validatePass) || $validatePass == false) {
                $this->clearResetSession();
                redirect('/forgetPassword.html');
            }
        } else {
            $this->clearResetSession();
            redirect('/forgetPassword.html');
        }

        session(C('RESET_PASSWORD_VALIDATE_PASSWORD'), true);
        $this->assign('mobile', $sessionMobile);
        $this->display();
    }

    /**
     * 清空重置密码相关session
     * @modify trainyao 2015-10-13 创建
     */
    private function clearResetSession() {
        session(C('RESET_PASSWORD_VCODE'), NULL);
        session(C('RESET_PASSWORD_SEND_TO'), NULL);
        session(C('RESET_PASSWORD_SEND_TIME'), NULL);
        session(C('RESET_PASSWORD_VALIDATE_PASS'), NULL);
    }

    /**
     * 申请账号页面
     * @modify zhangzhen 2017-01-04
     */
    public function apply() {
        $this->checkLogout();
        $this->display();
    }

    /**
     * @description 退出
     * @modify zhangzhen 2017-01-04
     */
    public function logout() {
        session(null);
        cookie(C('COOKIE_SERVER_REMEMBER_DEALER_UUID'), null);
        cookie(C('COOKIE_SERVER_REMEMBER_DEALER_USSID'), null);
        cookie(C('COOKIE_SERVER_REMEMBER_DEALER_USSPS'), null);
        cookie(C('COOKIE_SERVER_REMEMBER_DEALER_PSTM'), null);
        redirect('/dealer.html');
    }
}
